#include "Graph.h"

#include <QDebug>

#include "Node.h"

Graph::Graph()
{
}

Graph::~Graph()
{
    foreach (Node* node, nodes.values()) {
        delete node;
    }
}

void Graph::addNode(Node* node)
{

    nodes.insert(node->label(), node);
}

void Graph::startGibbsMetropolis(int iterations, int burnIn)
{
    QList<Node*> nodeList = nodes.values();
    for (int i = 0; i < iterations; i++) {
        foreach (Node* node, nodeList) {
            node->sample();

        }

    }

    foreach (Node* node, nodeList) {
        node->dropSampleHistoryUpTo(burnIn);
    }
}

int Graph::nodeCount()
{
    return nodes.count();
}

void Graph::addNodes(QList<Node*> muliple)
{
    foreach (Node* node, muliple) {
       this->addNode(node);
    }
}

Node * Graph::getNode(QString label)
{
    return nodes.value(label);
}
